from fastapi import APIRouter
from services.AIService import AIService
import time

router = APIRouter()


@router.get("/")
def read_root():
    return {"Hello": "World"}


@router.get("/getTaskId")
def get_task_id(desc: str):
    return AIService.imageSynthesis(desc)


@router.get("/getImg")
def getImg(task_id: str):
    return AIService.getImg(task_id)


@router.get("/createImg")
def createImg(desc: str):
    task_id = AIService.imageSynthesis(desc)
    time.sleep(8)  # 等待任务处理完成，实际应用中应使用更可靠的方式检查任务状态
    return AIService.getImg(task_id)
